class Solution:
    def spiralOrder(self, matrix):
        res = []
        while matrix:
            res += matrix.pop(0)
            matrix = list(zip(*matrix))[::-1]
        return res

# 打印矩阵
def printMatrix(m):
    for ele in m:
        for e in ele:
            print('%3d' % e, end='')
        print('')
# 转置矩阵
def transformMatrix(m):
    rt = [[] for i in m[0]]    # m[0] 有几个元素，说明原矩阵有多少列。此处创建转置矩阵的行
    for ele in m:
        for i in range(len(ele)):
            # rt[i] 代表新矩阵的第 i 行
            # ele[i] 代表原矩阵当前行的第 i 列
            rt[i].append(ele[i])
    return rt

# zip 转置
def transformMatrix2(m):
    # 逆向参数收集，将矩阵中多个列表转换成多个参数，传给 zip
    return list(zip(*m))


matrix = [[1,2,3],[4,5,6]]
printMatrix(matrix)
print('**'*20)
printMatrix(transformMatrix2(matrix))
print('**'*20)
printMatrix(transformMatrix2(matrix)[::-1])